//
//  NRWCarShareBottomView.m
//  New_Runway
//
//  Created by 张记 on 2018/5/28.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarShareBottomView.h"

@interface NRWCarShareBottomView ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
@property (weak, nonatomic) IBOutlet UIView *bottomview;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewH;
@property (weak, nonatomic) IBOutlet UIButton *wx;
@property (weak, nonatomic) IBOutlet UIButton *wxCircle;
@property (weak, nonatomic) IBOutlet UIButton *QQ;
@property (weak, nonatomic) IBOutlet UIButton *QQZone;
@property (weak, nonatomic) IBOutlet UILabel *wxL;
@property (weak, nonatomic) IBOutlet UILabel *wxcL;
@property (weak, nonatomic) IBOutlet UILabel *QQL;
@property (weak, nonatomic) IBOutlet UILabel *QQZL;

@end

@implementation NRWCarShareBottomView

-(void)awakeFromNib{
    [super awakeFromNib];
    UIColor *color = [UIColor blackColor];
    self.backgroundColor = [color colorWithAlphaComponent:0];
    self.bottomview.frame = CGRectMake(0, Screen_height, Screen_width, 270 + getSafeBottomMargin());
    self.viewH.constant = 270 + getSafeBottomMargin();
    self.contentF.delegate = self;
    self.contentF.tintColor = MAIN_NAV_COLOR();
    self.iconImage.layer.masksToBounds = YES;
    self.iconImage.layer.cornerRadius = 3;
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(event:)];
    [self addGestureRecognizer:tapGesture];
    [tapGesture setNumberOfTapsRequired:1];
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    if ([WXApi isWXAppInstalled]) {
        self.wx.hidden = self.wxCircle.hidden = self.wxL.hidden = self.wxcL.hidden = NO;
    }else{
        self.wx.hidden = self.wxCircle.hidden = self.wxL.hidden = self.wxcL.hidden = YES;

    }
}
-(void)setImageUrl:(NSString *)imageUrl{
    _imageUrl = imageUrl;
    
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImageApi,imageUrl]] placeholderImage:[UIImage imageNamed:@"tu"]];
}

//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat height = keyboardRect.size.height;
    [UIView animateWithDuration:0.5 animations:^{
   
        self.bottomview.frame = CGRectMake(0,Screen_height - 270 - height, Screen_width, 270);
    } completion:^(BOOL finished) {
        
    }];
    
}

//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification{
    [UIView animateWithDuration:0.5 animations:^{
      
        self.bottomview.frame = CGRectMake(0,Screen_height - 270 -  getSafeBottomMargin(), Screen_width, 270 +  getSafeBottomMargin());
    } completion:^(BOOL finished) {
        
    }];
    
}

- (void)event:(UITapGestureRecognizer *)gesture{
    [self.contentF resignFirstResponder];
}
-(void)show{
    [UIView animateWithDuration:0.5 animations:^{
        UIColor *color = [UIColor blackColor];
        self.backgroundColor = [color colorWithAlphaComponent:0.5];
        self.bottomview.frame = CGRectMake(0,Screen_height - 270 -  getSafeBottomMargin(), Screen_width, 270 +  getSafeBottomMargin());
    } completion:^(BOOL finished) {
      
    }];
    
   
}
- (IBAction)cancelClick:(id)sender {
    [self dismiss];
}

-(void)dismiss{
    [UIView animateWithDuration:0.3 animations:^{
        self.bottomview.frame = CGRectMake(0, Screen_height, Screen_width, 270 +  getSafeBottomMargin());
        UIColor *color = [UIColor blackColor];
        self.backgroundColor = [color colorWithAlphaComponent:0];
    } completion:^(BOOL finished) {
 
        [self removeFromSuperview];
    }];
    
}
-(void)textViewDidChange:(UITextView *)textView{
//    NSString  *nsTextContent = textView.text;
//    NSInteger existTextNum = nsTextContent.length;
//    if (existTextNum > 40)
//    {
//        NSString *s = [nsTextContent substringToIndex:40];
//        [textView setText:s];
//    }
//    self.content = textView.text;
}
- (IBAction)shareToWXFriendCircle:(id)sender {
    self.shareBlock(self.contentF.text, 1);
    [self dismiss];
}
- (IBAction)shareToWX:(UIButton *)sender {

    self.shareBlock(self.contentF.text, 2);
    [self dismiss];

}
- (IBAction)shareToQQ:(id)sender {
    self.shareBlock(self.contentF.text, 3);
    [self dismiss];

}
- (IBAction)shareToQQZone:(id)sender {
    self.shareBlock(self.contentF.text, 4);
    [self dismiss];

}

@end
